package com.mic.yzzn.plc.common.toolUtils;


/**
 * Created by ASH on 16/3/7.
 */
public class PLCNumberTransform
{
    public static final char[] HEX_TABLE = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};

    /**
     * 将十进制数转换成十六进制字符串
     * @param dec 十进制数
     * @return 十六进制字符串
     */
    public static String HEXStringFromDECNumber(int dec)
    {
        StringBuffer result = new StringBuffer();
        int temp = dec;
        int index = 0;
        
        while (temp > 0)
        {
            index = temp % 16;
            result.append(HEX_TABLE[index]);

            temp /= 16;
        }
        // 如果长度不足2则不足
        while (result.length() < 2)
		{
			result.append("0");
		}
        result.reverse();

        return result.toString();
    }
}
